﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

namespace Journeo_backend.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AttractionController : ControllerBase
    {
        private readonly IAttractionService _attractionService;
        private readonly ICoordinateConversionService _coordinateConversionService;

        public AttractionController(IAttractionService attractionService, ICoordinateConversionService coordinateConversionService)
        {
            _attractionService = attractionService;
            _coordinateConversionService = coordinateConversionService;
        }

        [HttpGet("{id}")]
        [SwaggerOperation(Summary = "获取景点信息", Description = "通过景点ID获取景点信息")]
        [SwaggerResponse(200, "获取成功", typeof(Response<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，景点ID无效")]
        public async Task<IActionResult> GetAttraction(long id)
        {
            var response = await _attractionService.GetAttractionDetailById(id);
            return Ok(response);
        }

        [HttpGet("region/{regionId}")]
        [SwaggerOperation(Summary = "根据地区获取景点", Description = "通过地区ID获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，地区ID无效")]
        public async Task<IActionResult> GetAttractionsByRegion(int pageNumber, int pageSize, long regionId)
        {
            var response = await _attractionService.GetAttractionsByRegion(pageNumber, pageSize, regionId);
            return Ok(response);
        }

        [HttpGet("search")]
        [SwaggerOperation(Summary = "搜索景点", Description = "通过搜索关键词搜索景点")]
        [SwaggerResponse(200, "搜索成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "搜索失败，搜索关键词无效")]
        public async Task<IActionResult> GetAttractionsBySearch(int pageNumber, int pageSize, string query)
        {
            var response = await _attractionService.GetAttractionsBySearch(pageNumber, pageSize, query);
            return Ok(response);
        }

        [HttpGet("rating")]
        [SwaggerOperation(Summary = "根据评分排序获取景点", Description = "通过景点评分倒序获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，评分排序无效")]
        public async Task<IActionResult> GetAttractionsByRating(int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsByRating(pageNumber, pageSize);
            return Ok(response);
        }

        [HttpGet("selectCount")]
        [SwaggerOperation(Summary = "根据选择次数排序获取景点", Description = "通过景点选择次数倒序获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，选择次数排序无效")]
        public async Task<IActionResult> GetAttractionsBySelectCount(int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsBySelectCount(pageNumber, pageSize);
            return Ok(response);
        }

        [HttpGet("distance")]
        [SwaggerOperation(Summary = "根据距离排序获取景点", Description = "通过景点距离倒序获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，距离排序无效")]
        public async Task<IActionResult> GetAttractionsByDistance(int pageNumber, int pageSize, decimal latitude, decimal longitude)
        {
            var response = await _attractionService.GetAttractionsByDistance(pageNumber, pageSize, latitude, longitude);
            return Ok(response);
        }

        [HttpGet("hot")]
        [SwaggerOperation(Summary = "根据热度排序获取景点", Description = "通过景点热度倒序获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，热度排序无效")]
        public async Task<IActionResult> GetAttractionsByHot(int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsByHot(pageNumber, pageSize);
            return Ok(response);
        }


        [HttpGet("rating/{regionId}")]
        [SwaggerOperation(Summary = "评分排序地区筛选", Description = "通过景点评分倒序和地区ID获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，评分排序或地区ID无效")]
        public async Task<IActionResult> GetAttractionsByRating(long regionId, int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsByRating(regionId, pageNumber, pageSize);
            return Ok(response);
        }

        [HttpGet("selectCount/{regionId}")]
        [SwaggerOperation(Summary = "选择次数排序地区筛选", Description = "通过景点选择次数倒序和地区ID获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，选择次数排序或地区ID无效")]
        public async Task<IActionResult> GetAttractionsBySelectCount(long regionId, int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsBySelectCount(regionId, pageNumber, pageSize);
            return Ok(response);
        }

        [HttpGet("distance/{regionId}")]
        [SwaggerOperation(Summary = "距离排序地区筛选", Description = "通过景点距离倒序和地区ID获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，距离排序或地区ID无效")]
        public async Task<IActionResult> GetAttractionsByDistance(long regionId, int pageNumber, int pageSize, decimal latitude, decimal longitude)
        {
            var response = await _attractionService.GetAttractionsByDistance(regionId, pageNumber, pageSize, latitude, longitude);
            return Ok(response);
        }

        [HttpGet("hot/{regionId}")]
        [SwaggerOperation(Summary = "热度排序地区筛选", Description = "通过景点热度倒序和地区ID获取景点")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionVO>))]
        [SwaggerResponse(400, "获取失败，热度排序或地区ID无效")]
        public async Task<IActionResult> GetAttractionsByHot(long regionId, int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetAttractionsByHot(regionId, pageNumber, pageSize);
            return Ok(response);
        }



        [HttpPost("likeAttraction")]
        [SwaggerOperation(Summary = "点赞景点", Description = "点赞景点")]
        [SwaggerResponse(200, "点赞成功", typeof(Response<string>))]
        [SwaggerResponse(400, "点赞失败，景点ID无效")]
        public async Task<IActionResult> LikeAttraction(long userId, long attractionId)
        {
            var response = await _attractionService.LikeAttraction(userId, attractionId);
            return Ok(response);
        }


        // 景点评论模块

        [HttpPost("createComment")]
        [SwaggerOperation(Summary = "创建景点评论", Description = "创建景点评论")]
        [SwaggerResponse(200, "创建成功", typeof(Response<AttractionCommentVO>))]
        [SwaggerResponse(400, "创建失败，评论无效")]
        public async Task<IActionResult> CreateAttractionComment(AttractionCommentDTO attractionCommentDTO)
        {
            var response = await _attractionService.CreateAttractionComment(attractionCommentDTO);
            return Ok(response);
        }

        [HttpDelete("deleteComment")]
        [SwaggerOperation(Summary = "删除景点评论", Description = "删除景点评论")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败，评论ID无效")]
        public async Task<IActionResult> DeleteAttractionComment(long commentId)
        {
            var response = await _attractionService.DeleteAttractionComment(commentId);
            return Ok(response);
        }

        [HttpGet("getComments")]
        [SwaggerOperation(Summary = "获取景点评论", Description = "获取景点评论")]
        [SwaggerResponse(200, "获取成功", typeof(PageResponse<AttractionCommentVO>))]
        [SwaggerResponse(400, "获取失败，景点ID无效")]
        public async Task<IActionResult> GetCommentsByAttraction(long attractionId, int pageNumber, int pageSize)
        {
            var response = await _attractionService.GetCommentsByAttraction(attractionId, pageNumber, pageSize);
            return Ok(response);
        }

        [HttpPost("uploadCommentImage")]
        [SwaggerOperation(Summary = "上传评论图片", Description = "上传评论图片")]
        [SwaggerResponse(200, "上传成功", typeof(Response<string>))]
        [SwaggerResponse(400, "上传失败，图片无效")]
        public async Task<IActionResult> UploadCommentImage(long userId, IFormFile file)
        {
            var response = await _attractionService.UploadCommentImage(userId, file);
            return Ok(response);
        }

        [HttpDelete("deleteCommentImage")]
        [SwaggerOperation(Summary = "删除评论图片", Description = "删除评论图片")]
        [SwaggerResponse(200, "删除成功", typeof(Response<string>))]
        [SwaggerResponse(400, "删除失败，图片URL无效")]
        public async Task<IActionResult> DeleteCommentImage(string imageUrl)
        {
            var response = await _attractionService.DeleteCommentImage(imageUrl);
            return Ok(response);
        }

        [HttpPost("likeComment")]
        [SwaggerOperation(Summary = "点赞评论", Description = "点赞评论")]
        [SwaggerResponse(200, "点赞成功", typeof(Response<string>))]
        [SwaggerResponse(400, "点赞失败，评论ID无效")]
        public async Task<IActionResult> LikeComment(long userId, long commentId)
        {
            var response = await _attractionService.LikeComment(userId, commentId);
            return Ok(response);
        }


        [HttpPost("convertCoordinates")]
        [SwaggerOperation(Summary = "转换坐标", Description = "将百度坐标转换为高德坐标")]
        [SwaggerResponse(200, "转换成功", typeof(Response<string>))]
        [SwaggerResponse(400, "转换失败，景点ID无效")]
        public async Task<IActionResult> ConvertCoordinates()
        {
            var response = await _coordinateConversionService.ConvertBaiduToAmap();
            return Ok(response);
        }
    }
}
